package com.huangbc.verificationcodeV2.controller;

import com.huangbc.internalcommon.dto.ResponseResult;
import com.huangbc.internalcommon.response.NumberCodeResponse;
import com.huangbc.verificationcodeV2.response.NumberCodeResponseV2;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author:Derek.huang on 2024/4/13 8:14
 */
@RestController
public class NumberCodeController {


//    @Value("${spring.cloud.nacos.discovery.cluster-name}")
//    private String clusterName;

    @Value("${server.port}")
    private String port;

    @GetMapping("/numberCode/{size}")
    public ResponseResult numberCode(@PathVariable("size") int size , HttpServletRequest request){

        String tag = request.getHeader("tag");
        System.out.println("验证码服务收到的tag："+tag);

        System.out.println("收到的验证码:" + port);
        // 生成验证码
        double mathRandom = (Math.random()*9 + 1) * (Math.pow(10,size-1));
        System.out.println(mathRandom);
        int resultInt = (int)mathRandom;
        System.out.println("数字验证码 code:"+resultInt);
//        System.out.println("数据中心，区域："+clusterName);

        // 定义返回值
        NumberCodeResponseV2 response = new NumberCodeResponseV2();
        response.setNumberCode(resultInt);
        return ResponseResult.success(response);
    }

}

